package com.zeedev.flyingsaucer.adapter;

import android.content.Context;
import android.database.Cursor;
import android.view.View;
import android.widget.ImageView;
import android.widget.ResourceCursorAdapter;
import android.widget.TextView;
import com.zeedev.flyingsaucer.ufoclub.R;
import mobi.zeedev.flyingsaucer.common.DataModule.MetaBeer;

public class UntastedCursorAdapter extends ResourceCursorAdapter {

    private final Context mContext;

    public UntastedCursorAdapter(Context context, int layout, Cursor c, boolean autoRequery) {
        super(context, layout, c, autoRequery);
        mContext = context;
    }

    @Override
    public void bindView(View view, Context context, Cursor cursor) {

        TextView beerNameView = (TextView) view.findViewById(R.id.textBeerName);
        ImageView beerContainerView = (ImageView) view.findViewById(R.id.textBeerContainer);

        beerNameView.setText(cursor.getString(cursor.getColumnIndex(MetaBeer.NAME)));
        Boolean isCan = cursor.getInt(cursor.getColumnIndex(MetaBeer.CAN)) == 1 ? true : false;
        Boolean isDraught = cursor.getInt(cursor.getColumnIndex(MetaBeer.DRAUGHT)) == 1 ? true : false;
        Boolean isBottled = cursor.getInt(cursor.getColumnIndex(MetaBeer.BOTTLE)) == 1 ? true : false;

        if (isCan) {
            beerContainerView.setImageDrawable(mContext.getResources().getDrawable(R.drawable.can));
        } else if (isDraught) {
            beerContainerView.setImageDrawable(mContext.getResources().getDrawable(R.drawable.draught));
        } else if (isBottled) {
            beerContainerView.setImageDrawable(mContext.getResources().getDrawable(R.drawable.bottle));
        }


    }

}
